function varargout = gui_FileRenameTool(varargin)
% GUI_FILERENAMETOOL M-file for gui_FileRenameTool.fig
%      GUI_FILERENAMETOOL, by itself, creates a new GUI_FILERENAMETOOL or raises the existing
%      singleton*.
%
%      H = GUI_FILERENAMETOOL returns the handle to a new GUI_FILERENAMETOOL or the handle to
%      the existing singleton*.
%
%      GUI_FILERENAMETOOL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_FILERENAMETOOL.M with the given input arguments.
%
%      GUI_FILERENAMETOOL('Property','Value',...) creates a new GUI_FILERENAMETOOL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before gui_FileRenameTool_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to gui_FileRenameTool_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help gui_FileRenameTool

% Last Modified by GUIDE v2.5 15-Sep-2008 18:42:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @gui_FileRenameTool_OpeningFcn, ...
                   'gui_OutputFcn',  @gui_FileRenameTool_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before gui_FileRenameTool is made visible.
function gui_FileRenameTool_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to gui_FileRenameTool (see VARARGIN)

handles.extstr = '*';
handles.flag_delete = 1;

handles.PathName = getappdata(0, 'lastPath');
if isempty(handles.PathName); handles.PathName = ['\']; end;
set(handles.dir_str, 'String', handles.PathName);
set(handles.delete, 'Value',1);

% Choose default command line output for gui_FileRenameTool
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes gui_FileRenameTool wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = gui_FileRenameTool_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in browse.
function browse_Callback(hObject, eventdata, handles)
% hObject    handle to browse (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.PathName = uigetdir(handles.PathName, 'Select the directory containing files to be renamed');
if handles.PathName == 0
    disp('No directory was selected, exiting.')        
    return
end
setappdata(0, 'lastPath', handles.PathName);
set(handles.dir_str, 'String', handles.PathName);
guidata(hObject, handles);


function old_pattern_Callback(hObject, eventdata, handles)
% hObject    handle to old_pattern (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of old_pattern as text
%        str2double(get(hObject,'String')) returns contents of old_pattern as a double
handles.OldPattern = get(hObject,'String');
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function old_pattern_CreateFcn(hObject, eventdata, handles)
% hObject    handle to old_pattern (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function new_pattern_Callback(hObject, eventdata, handles)
% hObject    handle to new_pattern (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of new_pattern as text
%        str2double(get(hObject,'String')) returns contents of new_pattern as a double
handles.NewPattern = get(hObject,'String');
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function new_pattern_CreateFcn(hObject, eventdata, handles)
% hObject    handle to new_pattern (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in run.
function run_Callback(hObject, eventdata, handles)
% hObject    handle to run (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

status = strvcat(get(handles.listbox1, 'string'),[' ']);
set(handles.listbox1,'string',status);
func_FileRenameTool(handles);
guidata(hObject, handles);


function ext_str_Callback(hObject, eventdata, handles)
% hObject    handle to ext_str (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ext_str as text
%        str2double(get(hObject,'String')) returns contents of ext_str as a double
handles.extstr = get(hObject,'String');
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function ext_str_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ext_str (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes during object deletion, before destroying properties.
function directory_DeleteFcn(hObject, eventdata, handles)
% hObject    handle to directory (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object creation, after setting all properties.
function directory_CreateFcn(hObject, eventdata, handles)
% hObject    handle to directory (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


% --- Executes on button press in delete.
function delete_Callback(hObject, eventdata, handles)
% hObject    handle to delete (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of delete
if get(hObject,'Value')==1
    handles.flag_delete = 1;
end
guidata(hObject, handles);

% --- Executes on button press in keep.
function keep_Callback(hObject, eventdata, handles)
% hObject    handle to keep (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of keep
if get(hObject,'Value')==1
    handles.flag_delete = 0;
end
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function delete_CreateFcn(hObject, eventdata, handles)
% hObject    handle to delete (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called







% --- Executes during object creation, after setting all properties.
function text6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called




% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to listbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes during object creation, after setting all properties.
function uipanel7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to uipanel7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called



% --- Executes on button press in all_files.
function all_files_Callback(hObject, eventdata, handles)
% hObject    handle to all_files (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of all_files
if get(hObject,'Value')==1
    handles.extstr = '*';
end

if get(hObject,'Value') == 1
    set(handles.ext_str, 'BackgroundColor', [0.925 0.914 0.847]);
end
guidata(hObject, handles);


% --- Executes on button press in extention.
function extention_Callback(hObject, eventdata, handles)
% hObject    handle to extention (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of extention
if get(hObject,'Value') == 1
    set(handles.ext_str, 'BackgroundColor', [1 1 1]);
    if isempty(get(handles.ext_str, 'String'))
        handles.extstr = '*';
    else
        handles.extstr = get(handles.ext_str, 'String');
    end
end
guidata(hObject, handles);


% --- Executes on button press in clear.
function clear_Callback(hObject, eventdata, handles)
% hObject    handle to clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.listbox1,'string',[]);
guidata(hObject, handles);
